package com.sun.dream.fish.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DataSourceConfig extends DruidDataSource {

    @Override
    public String getPassword() {
        PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
        SimpleStringPBEConfig config = new SimpleStringPBEConfig();
        config.setPassword("DSFSecret");
        config.setAlgorithm("PBEWithMD5AndDES");
        config.setKeyObtentionIterations("1000");
        config.setPoolSize("1");
        config.setProviderName("SunJCE");
        config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
        config.setStringOutputType("base64");
        encryptor.setConfig(config);
        return password.startsWith("ENC(") ? encryptor.decrypt(password.substring(password.indexOf("ENC(") + 4, password.length() - 1)) : password;
    }
}
